﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Film.Common;

namespace Film.Repository
{
    public class tblCountryRepository : Repository<tblCountry>
    {
        public tblCountry GetByCountryID(int countryID)
        {
            return dataContext.tblCountries.FirstOrDefault(x => x.CountryID == countryID);
        }

        public List<tblCountry> Filter(string keyWord, int start, int limit, out int count)
        {
            keyWord = UtilString.XacDinhNguyenAm(keyWord);
            var result = (from ds in dataContext.tblCountries
                          where (keyWord == "" ||
                          (keyWord != "" && (System.Data.Linq.SqlClient.SqlMethods.Like(ds.CountryName, "%" + keyWord + "%"))))
                          select ds);

            count = result.Count();
            return result.Skip(start).Take(limit).ToList();
        }
    }
}
